package com.marktotop.file.service.impl;

import com.marktotop.file.entity.TbUser;
import com.marktotop.file.mapper.TbUserMapper;
import com.marktotop.file.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbUserServiceImpl implements TbUserService {

    @Autowired
    private TbUserMapper userMapper;

    @Override
    public boolean insertUser(TbUser user) {
        return userMapper.insertUser(user);
    }

    @Override
    public List<TbUser> getByQuery(TbUser user) {
        return userMapper.findByQuery(user);
    }

    @Override
    public TbUser getUserById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public List<TbUser> getAllUser() {
        return userMapper.findAllUser();
    }

    @Override
    public Boolean deleteUserById(Integer id) {
        return userMapper.deleteById(id);
    }

    /**
     * 根据id更新用户信息
     * @param user
     * @return
     */
    @Override
    public Boolean updateUser(TbUser user) {
        //实现思路：先查后改
        TbUser findById = userMapper.findById(user.getId());
        if (findById != null){
            // 执行修改操作
            System.out.println(user);
            Boolean result = userMapper.updateUserById(user);
            System.out.println(result);
            return true;
        }
        return false;
    }
}
